package com.bytz.modules.cms.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bytz.common.api.vo.Result;
import com.bytz.modules.cms.common.constants.AdminAuthConstants;
import com.bytz.modules.cms.user.model.EcAuditModel;
import com.bytz.modules.cms.user.service.IEcAuditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @program: cms-backend
 *
 * @description:
 *
 * @author: KyleWang
 *
 * @create: 2022-11-04 11:12
 **/
@RestController
@Api(tags = "ec审批")
@RequestMapping("/ecAudit")
@PreAuthorize("hasAuthority('" + AdminAuthConstants.EcAudit.EDIT + "')")
public class EcAuditController {
    @Autowired
    IEcAuditService ecAuditService;


    @ApiOperation(value = "分页查询", notes = "分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<IPage<EcAuditModel>> page(@ModelAttribute EcAuditModel ecAuditModel,
                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                            HttpServletRequest req) throws Exception {
        IPage<EcAuditModel> ecAuditModelPage = new Page<>(pageNo, pageSize);
        Map<String, String[]> parameterMap = req.getParameterMap();

        return Result.ok(ecAuditService.queryPage(ecAuditModelPage, ecAuditModel, parameterMap));
    }

    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public Result<EcAuditModel> queryById(@RequestParam(value = "id") String id) {

        return Result.ok(ecAuditService.queryById(id));
    }
}
